﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace GodofTroll
{
    class FundoMovel
    {
        Game1 game1;
        Controles controles;

        private Texture2D fundoTexture1, fundoTexture2;
        public Vector2 fundoPosition, fundoPositionSave;
        private Rectangle fundoRectangle;
        private Point fundoPoint;

        public float velocidadeFundo;
        public int indiceFundo;
        public String[] imagemFundo;

        public FundoMovel(Texture2D fundoTextureConstrutor1, Texture2D fundoTextureConstrutor2, Point fundoPoint, Game1 game1)
        {
            this.fundoTexture1 = fundoTextureConstrutor1;
            this.fundoTexture2 = fundoTextureConstrutor2;
            this.fundoPoint = fundoPoint;
            this.game1 = game1;
            Initialize();
        }

        public void Initialize()
        {
            velocidadeFundo = 0.005f;
            indiceFundo = 0;
            imagemFundo = new String[3] {"imagemfundo01", "imagemfundo02", "imagemfundo03"};
        }

        public void Update(GameTime gameTime)
        {
            //controles.currentKeyboard = Keyboard.GetState();
            if (fundoPosition.X > fundoTexture1.Bounds.Width)
            {
                fundoTexture1 = fundoTexture2;
                fundoTexture2 = game1.Content.Load<Texture2D>(imagemFundo[indiceFundo++]);

                if (indiceFundo > imagemFundo.Length -1)
                {
                    indiceFundo = 0;
                }
                fundoPosition.X = 0;
            }

            // if (Keyboard.GetState().IsKeyDown(Keys.Right) && game1.personPosition.X > game1.GraphicsDevice.Viewport.Width / 2)
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                fundoPosition.X -= 0.05f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                fundoPosition.X += 0.05f;
            }
            //fundoPosition.X += (float)(gameTime.ElapsedGameTime.TotalMilliseconds * velocidadeFundo);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(fundoTexture1, fundoPosition, new Rectangle (0,0, fundoTexture1.Bounds.Width, fundoTexture1.Bounds.Height),
                Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);

            spriteBatch.Draw(fundoTexture2, (fundoPosition - new Vector2(fundoPositionSave.X, fundoPositionSave.Y)),
                new Rectangle ( 0,0, fundoTexture2.Bounds.Width, fundoTexture2.Bounds.Height),
                Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
        }
        
    }

}
